<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        list-style: none;
      }
      html {
        font-size: 26.6vw;
      }
      body {
        font-size: 16px;
      }
      .nav {
        display: flex;
        justify-content: center;
      }
      .nav li {
        height: 0.5rem;
        width: 100%;
        text-align: center;
        line-height: 0.5rem;
      }
      .nav .sty {
        background-color: orange;
        color: #fff;
      }
      .main {
        width: 100vw;
        height: 1rem;
      }
      .main ul {
        position: relative;
        height: 1rem;
        overflow: hidden;
      }
      .main ul li {
        position: absolute;
        top: 0;
        left: 0;
        width: 100vw;
        height: 1rem;
        font-size: 0.4rem;
        text-align: center;
        line-height: 1rem;
      }
      /* 显示动画 */
      .tap-enter {
        transform: translateX(100vw);
      }
      /* 隐藏动画 */
      .tap-leave-to {
        transform: translateX(-100vw);
      }
      /* 过渡时间 */
      .tap-leave-active,
      .tap-enter-active {
        transition: all 0.5s;
      }
      /* 显示动画 */
      .tap2-enter {
        transform: translateX(-100vw);
      }
      /* 隐藏动画 */
      .tap2-leave-to {
        transform: translateX(100vw);
      }
      /* 过渡时间 */
      .tap2-leave-active,
      .tap2-enter-active {
        transition: all 0.5s;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <my-tap v-for="item in list" :taplist="item"></my-tap>
    </div>

    <!-- 选项卡组件 -->
    <template id="tap">
      <div>
        <ul class="nav">
          <li
            v-for="(item,index) in taplist"
            :class="{sty:styCss==index}"
            @click="styCss=index"
            :key="index"
          >
            {{item}}
          </li>
        </ul>
        <div class="main">
          <ul>
            <!-- 过渡标签 -->
            <transition
              v-for="(item,index) in taplist"
              :name="tapName"
              :key="index"
            >
              <li v-show="styCss==index" @click="styCss=index">{{item}}</li>
            </transition>
          </ul>
        </div>
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
      const Tap = {
        template: "#tap",
        data() {
          return {
            styCss: 0,
            tapName: "tap",
          };
        },
        watch: {
          styCss(v, n) {
            this.tapName = v > n ? "tap" : "tap2";
          },
        },
        props: ["taplist"],
      };
      new Vue({
        el: "#app",
        data() {
          return {
            list: [
              ["语文", "数学", "英语"],
              ["地理", "历史", "政治"],
              ["生物", "化学", "物理", "社会", "雅思"],
            ],
          };
        },
        components: {
          "my-tap": Tap,
        },
      });
    </script>
  </body>
</html>
